<include file="Common:header" />

<include file="Common:nav" />
<div id="main1">
  <div class="tittle_cp"><span>在线留言</span><tt>Feedback</tt></div>
  <div class="conent_cp">
    <div class="sous"><a href="#">在线留言</a></div>
    <div class="conent_xx">
        <form id="message_from">
    <table width="779" border="0">
  <tr>
    <td width="121" height="36"><div align="right">标题：</div></td>
    <td width="648"><input type="text" name="msg_title" id="msg_title" class="text_ly"/></td>
  </tr>
   <tr>
    <td width="121"><div align="right">联系人：</div></td>
    <td width="648"><input type="text" name="msg_username" id="msg_username" class="text_ly"/></td>
  </tr>
        <tr>
            <td><div align="right">电话：</div></td>
            <td><input type="text" name="msg_mobile" id="msg_mobile" class="text_ly"/></td>
        </tr>
        <tr>
            <td><div align="right">性别：</div></td>
            <td>男<input type="radio" name="msg_sex" value="1" checked/>&nbsp;&nbsp;&nbsp;&nbsp;女<input type="radio" name="msg_sex" value="0"/></td>
        </tr>
  <tr>
    <td><div align="right">QQ号码：</div></td>
    <td><input type="text" name="msg_qq" class="text_ly"/></td>
  </tr>

  <tr>
    <td><div align="right">邮箱：</div></td>
    <td><input type="text" name="msg_email" id="msg_email" class="text_ly"/></td>
  </tr>

  <tr>
    <td><div align="right">描述：</div></td>
    <td><textarea class="text_ly" name="msg_content"  id="msg_content" style="width:440px; height:105px;"></textarea></td>
  </tr>
  <tr>
    <td height="61"><div align="right"></div></td>
    <td><input type="button" class="button_ti" id="button" value="提交"><input type="button" class="button_ti" value="重置"></td>
  </tr>
  <tr>
    <td height="67"><div align="right"></div></td>
    <td>&nbsp;</td>
  </tr>
</table>
        </form>
    </div>
</div>
<div style="clear:both; height:20px;"></div>
</div>
</div>
<div class="clearfix"></div>
<include file="Common:footer" />
</body>
</html>
<script type="text/javascript">
    // 验证中文名称
    function isChinaName(name) {
        var pattern = /^[\u4E00-\u9FA5]{1,6}$/;
        return pattern.test(name);
    }

    // 验证手机号
    function isPhoneNo(phone) {
        var pattern = /^1[34578]\d{9}$/;
        return pattern.test(phone);
    }

    function isEmail(email){
        var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
        return reg.test(email);
    }

    $(function() {
        $("#button").click(function() {
            var msg_title = $("#msg_title").val();
            var msg_username = $("#msg_username").val();
            var msg_mobile = $("#msg_mobile").val();
            var msg_content = $("#msg_content").val();
            var msg_email = $("#msg_email").val();

            if(msg_title == ''){
                layer.msg("请输入留言标题");
                $('#msg_title').focus();
                return false;
            }

            if(isChinaName(msg_username)==false){
                layer.msg('姓名请用中文!');
                $('#msg_username').focus();
                return false;
            }
            if(msg_mobile == ''){
                layer.msg('请输入手机号!');
                $('#msg_mobile').focus();
                return false;
            }
            if(isPhoneNo(msg_mobile)==false){
                layer.msg('手机号格式有误!');
                $('#msg_mobile').focus();
                return false;
            }

            if(msg_email != ''){
                if(isEmail(msg_email)==false){
                    layer.msg('邮箱格式有误!');
                    $('#msg_email').focus();
                    return false;
                }
            }

            if(msg_content ==''){
                layer.msg('留言内容必须输入!');
                return false;
            }
            $.post("{:U(MODULE_NAME.'/Index/message')}", $("#message_from").serialize(),function(data) {
                if(data.status==1){
                    layer.alert(data.info, {icon: 6});
                    $(".layui-layer-btn .layui-layer-btn0").click(function(){
                        location.href=location.href;
                    })
                }else{
                    layer.alert(data.info, {icon: 5});
                }
            });
        });
    })
</script>